package com.example.newhabitclock.CalendarView

import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.example.newhabitclock.HabitRoomPackage.Habit

//将viewpager2与calendarItemFragment绑定
class CalendarPagerAdapter(fragment:Fragment,private val habits:List<Habit>):FragmentStateAdapter(fragment) {
    override fun getItemCount(): Int {
        return habits.size
    }

    override fun createFragment(position: Int): Fragment {
        return CalendarItemFragment().apply {
            //将习惯id存入Fragment的参数中
            arguments = bundleOf("HABIT_ID" to habits[position].id)
        }
    }
}